<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>地址列表</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <link rel="stylesheet" href="../css/base.css">
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../js/public.js"></script>

    <style>
        body{

        }
        .list{overflow: hidden;border-bottom: 1px solid #f2f2f2;padding: .2rem;box-sizing: border-box;background: #fff}
        .list-fl{
            float: left;
            width: 15%;
            text-align: left;
        }
        .list-fl>img{
              width: .4rem;
            margin: .2rem 0;
        }
        .list-mid{
            width:75%;
            float: left;
        }
        .list-ri{
            width: 10%;
            float: left;
        }
        .list-ri>a>img{
            width: .34rem;
            margin: .2rem 0;
        }
        .name{
            font-size: 14px;
        }
        .address{
            font-size: 12px;
        }
        .add-img{
            width: .20px;
            height: 20px;
            position: absolute;
            top: 10px;
        }
        .add-font{
            font-size: 12px;
            text-align: center;
            display: block;
            background: #fa4535;
            color: #fff;
            margin: 10px 20px 0;
            position: fixed;
            left: 10px;
            right: 10px;
            bottom: 20px;
        }
        .div-add{
            height: 40px;
            line-height: 40px;
            width: 80%;
            margin: 10px auto;
            text-align: center;
        }
        .dels{
            font-size: 12px;
            color: #fa4535;
            position: absolute;
            right: 25px;
            bottom: 0;
        }
    </style>
</head>
<style>

</style>
<body>
<div id="main" style="overflow: hidden">

</div>

<!--    <p class="div-add">
        &lt;!&ndash;<img src="../img/addimg@2x.png" class="add-img">&ndash;&gt;

            <span class="add-font">新增地址</span>

    </p>-->
<a href="personaladdress.html">
<p class="tip flex" style="line-height: .88rem;background: #fff;padding: 0 .2rem;position: relative;" onclick='javascript:window.location.href="personaladdress.html"'>
    <img src="../img/添加@2x.png" style="width: 20px;height: 20px;vertical-align: middle;">
    <span class="p2" style="vertical-align: middle;" >添加地址</span>
    <img src="../img/下一步@2x.png" style="width: 9px;position: absolute;right: 0;top: .32rem;right: .2rem;">
</p>
</a>
<script>

    $(function (){
        var isPageHide = false;
        window.addEventListener('pageshow', function () {
            if (isPageHide) {
                window.location.reload();
            }
        });
        window.addEventListener('pagehide', function () {
            isPageHide = true;
        });
        /**
         * 获取地址列表
         * **/
        var uid = sessionStorage.getItem("uid");
        $.ajax({
            url:base_url+"ZITAOHUI/address/list",
            data:{
                uid:uid
            },
            dataType:"json",
            success:function (data){
                console.log(data);
               if(data.code == 1){
                   var _d = data.extend.data;
                   if(_d.length == 0){
                       $("#main").html('<div style="text-align: center;margin: 20px 0;">暂无地址</div>')
                       return false;
                   }
                   $.each(_d,function(k,v){
                       $("#main").append('  <div class="list" style="position: relative;">' +
                           '        <div class="list-fl">' +
                           '            <img src="../img/全选%2002@2x.png" >' +
                           '        </div>'+
                           '        <div class="list-mid">' +
                           '            <p class="name">'+'<span>'+v.name+'</span>'+ '<span>'+v.phone+'</span>' +'</p>' +
                           '            <p class="address">'+v.addDesc+'</p>' +
                           '        </div>' +
                           '        <div class="list-ri">' +
//                           '<a href='+"personaladdress.html?id="+v.addId+"&postCode="+v.postCode+'>'+
                           '            <img style="width: .36rem;" src="../img/xiug.png" data-id="'+v.addId+'" onclick="bj(this)" data-code="'+v.postCode+'" data-name="'+v.name+'"  data-phone="'+v.phone+'" data-address="'+v.addDesc+'">' +
//                           '</a>'+
                               '<span class="dels" data-id="'+v.addId+'" onclick="delAddress(this)">'+'删除'+'</span>'+
                           '        </div>' +
                           '    </div>')
                   })
               }else{
                   alert(data.msg);
               }
            },
            error:function (error){

            }
        })
    });
    function delAddress(obj){
        var $id = $(obj).attr("data-id");
        console.log($id);
        $.ajax({
            url:base_url+"ZITAOHUI/user/deleteAddress",
            type:"post",
            data:{
                addressId:$id,
                uid:sessionStorage.getItem("uid")
            },
            dataType:"json",
            success:function (data){
                if(data.code == 1){
                    alert("删除成功");
                    window.location.href = window.location.href;
                }
            },
            error:function (error){
                console.log(error);
            }
        })
    }
    function bj (obj){
        var name =encodeURI(encodeURI($(obj).attr('data-name')));
        var phone = $(obj).attr('data-phone');
        var code = $(obj).attr("data-code");
        var address = encodeURI(encodeURI($(obj).attr('data-address')));
        var $id = $(obj).attr('data-id');
        window.location.href = "personaladdress.html?name="+name+"&phone="+phone+"&code="+code+"&address="+address+"&id="+$id;
    }
</script>


</body>
</html>